package pro.lingwu.rainbowmall.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.cors.CorsConfiguration
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
import org.springframework.web.filter.CorsFilter

/**
 * There is a configuration for cors.
 * I use this configuration in Debug mode for convenience.
 *
 * @author lingwu
 */
@Configuration
class CorsConfig {

    @Bean fun corsFilter(): CorsFilter {
        val source = UrlBasedCorsConfigurationSource()
        val configuration = CorsConfiguration()
        configuration.addAllowedMethod("*")
        configuration.addAllowedOrigin("*")
        configuration.addAllowedHeader("*")
        source.registerCorsConfiguration("/**", configuration)
        return CorsFilter(source)
    }

}